package com.firewolf.oa.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.firewolf.oa.base.impl.BaseServiceImpl;
import com.firewolf.oa.dao.DepartmentDao;
import com.firewolf.oa.entities.Department;
import com.firewolf.oa.service.DepartmentService;
@Service
@Transactional
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService{

	@Autowired
	private DepartmentDao departmentDao;
	
	@Override
	public List<Department> findTopDepartments() {
		return departmentDao.findTopDepartments();
	}

	@Override
	public List<Department> findDeptsByParentId(Long parentId) {
		if(parentId == null)
			return departmentDao.findTopDepartments();
		Department dept = departmentDao.findById(parentId);
		return Arrays.asList(dept.getChildren().toArray(new Department[0]));
	}
}
